capture log close
clear all
set more off
pause off

local path ""
local log ""
local data ""

/* 
Create Table A1
*/

use "`data'\EIN_collapsed.dta", clear
destring EIN, gen(ein) 
tempfile ein 
save `ein' 


* Load merged data set - list of EINs, EIN level claim and retirement variables, EIN level Form 5500 variables
import delimited "`data'\ein_avg.csv", clear

rename ein_60 ein 
keep mean_retire_age_65 mean_retire_age_66 mean_claim_age_65 mean_claim_age_66 ein new_fra 
reshape wide mean_retire_age_65 mean_retire_age_66 mean_claim_age_65 mean_claim_age_66, i(ein) j(new_fra) 

foreach type in retire claim { 
	foreach age in 65 66 {
		rename mean_`type'_age_`age'0 `type'_`age'_pre 
		rename mean_`type'_age_`age'1 `type'_`age'_post
		gen delt_`type'_`age' = `type'_`age'_post - `type'_`age'_pre
	}
}

merge 1:1 ein using `ein' 
drop if _merge == 2 
gen byte match_swap_variable = (_merge ==3) 
drop _merge

* convert dollar amounts to $10M
local dollar mean_net_asset employer_contribution any_contribution
foreach x in `dollar' {
gen `x'_adjusted = `x'/10000000
}

* convert number of employees to thousands
local nemp num_employee num_qual_employee
foreach x in `nemp' {
gen `x'_adjusted = `x'/1000
}

* Swap "match_swap_variable" with variable that is an indicator for whether there was a match
local match match_swap_variable

* Replace with zeros missings that are due to not having a match
local XX retiree_benefit_ind DB_ind DC_ind ///
collective_ind profitability growth terminated ///
mean_net_asset_adjusted employer_contribution_adjusted any_contribution_adjusted ///
num_employee_adjusted num_qual_employee_adjusted

foreach x in `XX' {
replace `x' = 0 if match==0
}

/* Panel A */
foreach y in delt_claim_65 delt_claim_66 {
eststo: quietly reg `y' match (c.retiree_benefit_ind c.DB_ind c.DC_ind c.collective_ind ///
c.num_employee_adjusted c.num_qual_employee_adjusted ///
c.mean_net_asset_adjusted c.employer_contribution_adjusted c.any_contribution_adjusted ///
c.terminated)#c.match if match==1, robust
}
esttab using "`path'\Table_A1_PanelA.rtf", se replace ///
star(* 0.10 ** 0.05 *** 0.01)

/* Panel B */
foreach y in delt_retire_65 delt_retire_66 {
eststo: quietly reg `y' match (c.retiree_benefit_ind c.DB_ind c.DC_ind c.collective_ind ///
c.num_employee_adjusted c.num_qual_employee_adjusted ///
c.mean_net_asset_adjusted c.employer_contribution_adjusted c.any_contribution_adjusted ///
c.terminated)#c.match if match==1, robust
}
esttab using "`path'\Table_A1_PanelB.rtf", se replace ///
star(* 0.10 ** 0.05 *** 0.01)






